package com.qf.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.netflix.discovery.converters.Auto;
import com.qf.entity.User;
import com.qf.feign.api.IUserService;
import com.qf.resp.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

//    @RequestMapping("/toUserList")
//    public String toUserList(){
//        System.out.println("UserController.toUserList");
//        return "user/userList";
//    }

    @Autowired
    private IUserService userService;

    @RequestMapping("/getUserPage")
    public String getUserPage(Page<User>page, ModelMap modelMap){

        // 1.先获取数据
        page= userService.getUserPage(page);

        // 2.把page放入到域中
        modelMap.put("page",page);

        List<User> records = page.getRecords();
        // 3.跳转到页面展示数据
        return "user/userList";
    }

    @RequestMapping("/addUser")
    @ResponseBody
    public ResultEntity addUser(User user){
        return userService.addUser(user);
//        System.out.println("UserController.addUser");
//        return ResultEntity.error("添加用户失败");
    }
}
